<!--退件提交"-->
<template>
  <div>
    <el-form :model="checkForm" label-width="100px" class="demo-ruleForm">
      <el-form-item label="办理结果" prop="approveStatus"  :rules="[{ required: true, message: '请选择办理结果', trigger: 'change' }]">
        <el-radio-group v-model="checkForm.approveStatus"  @change="handleChange">
          <el-radio label="20" class="red">删除</el-radio>
          <el-radio label="9" class="red">再次提交</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm(checkForm)" v-if="this.checkForm.approveStatus=='9'">编辑</el-button>
        <el-button type="danger" @click="submitForm(checkForm)" v-if="this.checkForm.approveStatus=='20'">删除</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import { deleteByProjectId,backProject } from '@/api/project';
export default {
  props: {
     projectId: undefined,
     taskId: undefined
  },
  data() {
    return {
      checkForm: {
        approveStatus: undefined,
        projectId: undefined,
      },
    };
  },

  methods: {
    submitForm() {
      if (this.checkForm.approveStatus == undefined) {
        this.$message.error('请选择办理结果！');
        return;
      }
      if (this.checkForm.approveStatus == 20) {
        this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          // 删除项目
          // this.$message.error('此操作暂不可用哦');
          deleteByProjectId(this.projectId).then((data) => {
            this.$message.success('操作成功');
            this.$store.dispatch('delVisitedViews', this.$route);
            this.$router.go(-1);
          });
        });
      }
      if (this.checkForm.approveStatus == 9) {
        this.checkForm.projectId = this.projectId,
        this.checkForm.taskId = this.taskId,
        backProject(this.projectId).then((data) => {
          this.$router.push({path:"/project/add",query:{submitProjectId:data.data.id,taskId:this.taskId}})
        });
      }

      // else {
      //   this.checkForm.id = this.projectId,
      //   // 1 先备份项目
      //   backProject(this.checkForm).then((data) => {
      //     // 2 跳转到便捷页面  待修改
      //       this.$router.push({path:"/project/add",query:{submitProjectId:data.data.id}})
      //     });
      // }
    },
    handleChange(node) {
      this.checkForm.approveStatus = node;
    },
  },
};
</script>
